<html>
<head><meta charset="utf-8"><title>How would I serialize a rustc data structure? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html">How would I serialize a rustc data structure?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="199944553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199944553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199944553">(Jun 05 2020 at 23:24)</a>:</h4>
<p>In <a href="https://github.com/rust-lang/rust/issues/65983#issuecomment-638352731">https://github.com/rust-lang/rust/issues/65983#issuecomment-638352731</a>, <span class="user-mention" data-user-id="132040">@Manish Goregaokar</span> mentioned a 'resolver tree' in <code>rustc_resolve</code>. Does anyone know what that is? I see a <code>Resolver</code> that implements <code>DefIdTree</code>, is that it?</p>
<p>There was also something about 'self-referential arena's which I don't quite understand - is this arenas like the memory allocation strategy? What makes those self-referential?</p>



<a name="199944594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199944594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199944594">(Jun 05 2020 at 23:25)</a>:</h4>
<p>Partially related - how do I serialize a rustc data structure? I assume it's not as simple as <code>derive(rustc_serialize::Serialize)</code>?</p>



<a name="199944595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199944595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manish Goregaokar <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199944595">(Jun 05 2020 at 23:25)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/struct.ModuleData.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/struct.ModuleData.html</a></p>



<a name="199944679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199944679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manish Goregaokar <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199944679">(Jun 05 2020 at 23:26)</a>:</h4>
<p>No the whole issue here is that all the resolution information is stored in an arena, it's not something that's easy to serialize. We need to convert it to a datastructure that _is_ easy to serialize and query, one that _just_ has the list of resolutions for a given module defid.</p>



<a name="199944746"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199944746" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199944746">(Jun 05 2020 at 23:28)</a>:</h4>
<p>Ok, and arenas are self-referential because they use indices instead of the data itself?</p>



<a name="199945010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199945010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199945010">(Jun 05 2020 at 23:33)</a>:</h4>
<p>What's the trait I need to implement?</p>



<a name="199945035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199945035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199945035">(Jun 05 2020 at 23:33)</a>:</h4>
<p>looks like Decodable and Encodable</p>



<a name="199945325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199945325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199945325">(Jun 05 2020 at 23:38)</a>:</h4>
<p>I can't even import rustc_serialize :(</p>
<div class="codehilite"><pre><span></span><code>error[E0463]: can&#39;t find crate for `rustc_serialize`
  --&gt; src/librustc_resolve/lib.rs:56:1
   |
56 | extern crate rustc_serialize;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can&#39;t find crate
</code></pre></div>



<a name="199945874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199945874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manish Goregaokar <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199945874">(Jun 05 2020 at 23:48)</a>:</h4>
<p>They use references.</p>
<p>Traits aren't the important part. The work is in creating a data strcture, we'll figure out how it can go into emtadata later.</p>



<a name="199946668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199946668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199946668">(Jun 06 2020 at 00:02)</a>:</h4>
<p>Do you have some other examples of serializable structures you can point me to?</p>



<a name="199947863"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199947863" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199947863">(Jun 06 2020 at 00:29)</a>:</h4>
<p>My idea for making <code>parent</code> non-referential was to have one structure that stored all modules and store an index into that structure</p>



<a name="199947882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199947882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199947882">(Jun 06 2020 at 00:30)</a>:</h4>
<p>something like this:</p>
<div class="codehilite"><pre><span></span><code><span class="sd">/// A `ModuleData` that is non self-referential</span>
<span class="k">struct</span> <span class="nc">OwnedModuleData</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">parent</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="n">ModuleIndex</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="o">..</span><span class="p">.</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="sd">/// An opaque reference to an `OwnedModuleData`. To be used in conjunction with a `ModuleStore`.</span>
<span class="k">struct</span> <span class="nc">ModuleIndex</span><span class="p">(</span><span class="kt">usize</span><span class="p">);</span><span class="w"></span>

<span class="sd">/// A list of all modules needed to serialize a specific module</span>
<span class="k">struct</span> <span class="nc">ModuleStore</span><span class="p">(</span><span class="nb">Vec</span><span class="o">&lt;</span><span class="n">OwnedModuleData</span><span class="o">&gt;</span><span class="p">);</span><span class="w"></span>
</code></pre></div>



<a name="199947959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199947959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199947959">(Jun 06 2020 at 00:31)</a>:</h4>
<p>and all the structs with lifetime parameters aren't a big deal, it's only the references that matter</p>



<a name="199948000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199948000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199948000">(Jun 06 2020 at 00:32)</a>:</h4>
<p>so that leaves</p>
<div class="codehilite"><pre><span></span><code><span class="w">    </span><span class="n">glob_importers</span>: <span class="nc">RefCell</span><span class="o">&lt;</span><span class="nb">Vec</span><span class="o">&lt;&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="n">Import</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="o">&gt;&gt;&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">globs</span>: <span class="nc">RefCell</span><span class="o">&lt;</span><span class="nb">Vec</span><span class="o">&lt;&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="n">Import</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="o">&gt;&gt;&gt;</span><span class="p">,</span><span class="w"></span>

<span class="w">    </span><span class="c1">// Used to memoize the traits in this module for faster searches through all traits in scope.</span>
<span class="w">    </span><span class="n">traits</span>: <span class="nc">RefCell</span><span class="o">&lt;</span><span class="nb">Option</span><span class="o">&lt;</span><span class="nb">Box</span><span class="o">&lt;</span><span class="p">[(</span><span class="n">Ident</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="n">NameBinding</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="o">&gt;</span><span class="p">)]</span><span class="o">&gt;&gt;&gt;</span><span class="w"></span>
</code></pre></div>



<a name="199948013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199948013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199948013">(Jun 06 2020 at 00:32)</a>:</h4>
<p>From the comment it seems like <code>traits</code> might not need to be stored? Since it's only a cache and can be recalculated?</p>



<a name="199948030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199948030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199948030">(Jun 06 2020 at 00:33)</a>:</h4>
<p>Do you know why <code>glob_importers</code> and <code>globs</code> are RefCells?</p>



<a name="199948257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199948257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199948257">(Jun 06 2020 at 00:39)</a>:</h4>
<p>update: this is why <code>globs</code> is a RefCell: <a href="https://hastebin.com/gorakaqiha.coffeescript">https://hastebin.com/gorakaqiha.coffeescript</a></p>



<a name="199950185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199950185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199950185">(Jun 06 2020 at 01:31)</a>:</h4>
<blockquote>
<p>and all the structs with lifetime parameters aren't a big deal, it's only the references that matter</p>
</blockquote>
<p>This appears to be incorrect, I don't see any easy way to make any of these owned.</p>



<a name="199950253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199950253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199950253">(Jun 06 2020 at 01:32)</a>:</h4>
<p>What if I narrowed the scope and instead only tried to serialize <code>Resolutions</code>? I think that's all rustdoc really needs</p>



<a name="199950257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199950257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199950257">(Jun 06 2020 at 01:32)</a>:</h4>
<p>unless i'm misunderstanding glob imports</p>



<a name="199950277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199950277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199950277">(Jun 06 2020 at 01:34)</a>:</h4>
<p>oh well that has a <code>&amp;'a Import&lt;'a&gt;</code> anyway so I'd have to solve this problem sooner or later</p>



<a name="199950469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199950469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199950469">(Jun 06 2020 at 01:39)</a>:</h4>
<p>I'm finding it really hard to understand the lifetimes because of all the <code>RefCell</code></p>



<a name="199950514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199950514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199950514">(Jun 06 2020 at 01:40)</a>:</h4>
<p>The <code>type Module = &amp;ModuleData</code> alias is convenient but means that all the mutability is <em>forced</em> to use refcell</p>



<a name="199950962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/199950962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#199950962">(Jun 06 2020 at 01:54)</a>:</h4>
<p>I'm seeing something called <code>ResolverOutputs</code> which has no borrows and looks like basically what we'd need, can I reuse that?</p>



<a name="200035185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200035185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manish Goregaokar <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200035185">(Jun 07 2020 at 18:03)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> Given your comments here and in the github thread I think you're overfocusing on the "serialize" part of it. The high level thing is that rustdoc needs to be able to resolve reexport documentation against their original module map, which is not available in cross-crate scenarios. Serializing is necessary to stick it into the rlib so we can get it back. The important thing is getting it in a state where it's fully owned with no self references</p>



<a name="200035240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200035240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manish Goregaokar <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200035240">(Jun 07 2020 at 18:04)</a>:</h4>
<p>I don't think we actually should be trying to serialize the _entire_ Resolver. Rather, we should be reading it and producing a new type that _can_ be serialized. The <code>traits</code> field is unnecessary. <code>globs</code> kind of is, sadly.</p>



<a name="200035512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200035512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manish Goregaokar <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200035512">(Jun 07 2020 at 18:12)</a>:</h4>
<p>You really need to talk to compiler team members about this, though.</p>



<a name="200039983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200039983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200039983">(Jun 07 2020 at 20:07)</a>:</h4>
<p>I'm really confused how serialization is related at all, to be honest</p>



<a name="200039986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200039986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200039986">(Jun 07 2020 at 20:08)</a>:</h4>
<p>The reason I keep focusing on it is I'm trying to find out how it's related</p>



<a name="200040026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200040026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200040026">(Jun 07 2020 at 20:08)</a>:</h4>
<p>none of the changes I made in <a href="https://github.com/rust-lang/rust/pull/73101/">https://github.com/rust-lang/rust/pull/73101/</a> were related to serialization</p>



<a name="200040103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200040103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200040103">(Jun 07 2020 at 20:10)</a>:</h4>
<p>also I might be confused - I thought you were a compiler team member? <span class="user-mention" data-user-id="132040">@Manish Goregaokar</span></p>



<a name="200040251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200040251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200040251">(Jun 07 2020 at 20:14)</a>:</h4>
<p>ah ok you're part of the clippy team, that's why I was confused (plus core of course)</p>



<a name="200043055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200043055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manish Goregaokar <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200043055">(Jun 07 2020 at 21:22)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> I mentioned serialization because this is information downstream crates do not have, and the way for them to get it is through metadata, and to put something in metadata we need to be able to serialize it cross crate (so, no self references)</p>



<a name="200043163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200043163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manish Goregaokar <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200043163">(Jun 07 2020 at 21:24)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> it's not clear to me how that PR fixes this bug. The test case is:</p>
<div class="codehilite"><pre><span></span><code>// crate a:
pub struct Foo;

/// Link to [Foo]
pub struct Bar;

// crate b:
pub use a::Bar;
</code></pre></div>


<p>the docs for <code>b::Bar</code> should link correctly to <code>a::Foo</code>.</p>



<a name="200043195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200043195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manish Goregaokar <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200043195">(Jun 07 2020 at 21:25)</a>:</h4>
<p>Yeah I've never been compiler team. I'm capable of reviewing for most of the compiler, and I understand the resolver, but not well enough for something like this.</p>



<a name="200043271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200043271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200043271">(Jun 07 2020 at 21:27)</a>:</h4>
<p>this is what my PR outputs for that test case: <a href="/user_uploads/4715/D4aqBTulCHlvBGELiSuPXB4R/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/D4aqBTulCHlvBGELiSuPXB4R/image.png" title="image.png"><img src="/user_uploads/4715/D4aqBTulCHlvBGELiSuPXB4R/image.png"></a></div>



<a name="200043284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200043284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200043284">(Jun 07 2020 at 21:27)</a>:</h4>
<p>the link is to <code>/a/struct.Foo.html</code>.</p>



<a name="200043313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200043313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200043313">(Jun 07 2020 at 21:28)</a>:</h4>
<p>I'm not sure how to add test cases with multiple crates, I can look into that</p>



<a name="200043342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200043342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200043342">(Jun 07 2020 at 21:28)</a>:</h4>
<p>the reason my PR works is because it resolves types relative to the other crate (<code>a</code>), not to the current crate (<code>b</code>)</p>



<a name="200043357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200043357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200043357">(Jun 07 2020 at 21:29)</a>:</h4>
<p>which is correct because the docs were written in <code>a</code>, not in <code>b</code>. So if we try to resolve relative to <code>b</code> none of the same items will be in scope.</p>



<a name="200054790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200054790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manish Goregaokar <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200054790">(Jun 08 2020 at 03:07)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> huh, that surprises me. Does that even work when A and B are within some deeper modules (all public)?</p>



<a name="200054792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200054792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manish Goregaokar <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200054792">(Jun 08 2020 at 03:07)</a>:</h4>
<p>I think I have a guess here as to what's happening: the ExportMap already has what we needed to some extent</p>



<a name="200054842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200054842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manish Goregaokar <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200054842">(Jun 08 2020 at 03:08)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> another test case would be to stick Bar in a private module, and re-export it from the top level, and have Foo in a public module with Bar using <code>Foo</code> in docs with a <code>use foomod::Foo</code> in scope.</p>



<a name="200054852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200054852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200054852">(Jun 08 2020 at 03:09)</a>:</h4>
<p>Sounds good, I'll try that tomorrow</p>



<a name="200054970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200054970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200054970">(Jun 08 2020 at 03:13)</a>:</h4>
<p>Also <code>--no-deps</code> breaks things for reasons I don't understand</p>



<a name="200054977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200054977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200054977">(Jun 08 2020 at 03:14)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/73101#issuecomment-640330018">https://github.com/rust-lang/rust/pull/73101#issuecomment-640330018</a></p>



<a name="200055201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200055201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200055201">(Jun 08 2020 at 03:21)</a>:</h4>
<p>Only if the item wasn't inlined though? That's weird, that means it can be fixed in rustdoc though</p>



<a name="200055203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200055203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200055203">(Jun 08 2020 at 03:21)</a>:</h4>
<p>Only if the item wasn't inlined though? That's weird, that means it can be fixed in rustdoc though</p>



<a name="200123662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20would%20I%20serialize%20a%20rustc%20data%20structure%3F/near/200123662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manish Goregaokar <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20would.20I.20serialize.20a.20rustc.20data.20structure.3F.html#200123662">(Jun 08 2020 at 16:33)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span>  oh btw i am not watching htis channel, i won't see things you don't ping me on</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>